package com.spzx.product.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.dto.OrderStockDTO;
import com.spzx.product.api.domain.query.ProductSkuQuery;
import com.spzx.product.api.domain.vo.ProductSkuVO;
import com.spzx.product.api.factory.RemoteProductFallbackFactory;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@FeignClient(contextId = "remoteProductService"
        ,value = ServiceNameConstants.PRODUCT_SERVICE //注册中心的服务名
        , fallbackFactory = RemoteProductFallbackFactory.class //降级工厂
    )
public interface RemoteProductService {


    @Operation(summary = "内部调用接口：验库存锁库存")
    @PostMapping("stock/checkAndLockStock")
    public R<List<OrderStockDTO>> checkAndLockStock(@RequestBody List<OrderStockDTO> orderStockDTOS);


    //所有的内部调用接口 都会经过InnerAuth切面类处理 请求头必须携带他要求的字符串
//    @Operation(summary = "内部调用接口：查询首页热门数据")
//    @GetMapping("product/listIndexSkus")
//    public R<List<ProductSku>> listIndexSkus(@RequestHeader(SecurityConstants.FROM_SOURCE)
//                                                 String source);
    @Operation(summary = "内部调用接口：查询一组sku的价格")
    @PostMapping("product/getSkusPrice")
    public R<Map<Long , BigDecimal>> getSkusPrice(@RequestBody List<Long> skuIds);


    @Operation(summary = "内部调用接口：查询首页热门数据")
    @GetMapping("product/listIndexSkus")
    public R<List<ProductSku>> listIndexSkus();
    //@SpringQueryMap: openfeign将 对象转为 请求参数的注解
    @Operation(summary = "内部调用接口：条件查询sku分页数据")
    @GetMapping("product/listSkus")
    public R<Page<ProductSku>> listSkus(@SpringQueryMap ProductSkuQuery query);

    @Operation(summary = "内部调用接口：查询sku详情页数据")
    @GetMapping("product/getSkuDetails/{skuId}")
    public R<ProductSkuVO> getSkuDetails(@PathVariable("skuId")Long skuId);
}
